package cn.wolfcode.trip.admin.controller;


import cn.wolfcode.trip.base.domain.Order;
import cn.wolfcode.trip.base.query.OrderQueryObject;
import cn.wolfcode.trip.base.query.QueryObject;
import cn.wolfcode.trip.base.service.IOrderService;
import cn.wolfcode.trip.base.util.JsonResult;
import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonAnyFormatVisitor;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/order")
public class OrderController {

    @Autowired
    private IOrderService orderService;

    /**
     * 展示所有订单数据
     * @param qo
     * @param model
     * @return
     */
    @RequestMapping("/list")
    public String listAll(@ModelAttribute("qo") OrderQueryObject qo, Model model){
        PageInfo<Order> pageInfo = orderService.query(qo);
        model.addAttribute("pageInfo",orderService.query(qo));
        return "/order/list";
    }

    @RequestMapping("/UpdateOrder")
    @ResponseBody
    public Object UpdateOrder(Order order){
        JsonResult jsonResult = new JsonResult();
        try {
            orderService.UpdateOrder(order);
            return jsonResult ;
        }catch (Exception e){
            e.printStackTrace();
            return jsonResult.mark("网络繁忙");
        }
    }

}
